// pages/cleanTaskdetail/cleanTaskdetail.js
let httprequest = require('../../utils/http_utils.js')
let regeneratorRuntime = require('../../utils/runtime.js');
let utils = require('../../utils/util')
let CryptoJS = require('../../utils/aes_util.js') //参数加密
let dateutil = require('../../utils/date_util.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    title: '',
    cleanitems: [{
        name: '已完成',
        value: 1
      },
      {
        name: '未完成',
        value: 0
      }
    ],
    cleanResult: '0', //保洁项是否异常
    TaskRowGuid: '', //保洁任务guid
    CleanFileData: [], //保洁项信息
    DetailData: [], //租户评价信息
    MainData: [], //保洁任务详情
    RatingFileData: [], //租户评价信息
    UploadUrl: httprequest.uploadUrl,
  },

  //获取保洁历史任务详情
  GetHistoryCleanTaskDetails() {
    var that = this
    var param = {
      TaskRowGuid: that.data.TaskRowGuid
    }
    httprequest.GetValidateRequest(httprequest.apiInfo.GetHistoryCleanTaskDetailsApi, param,
      function(res) {
        console.log('获取保洁历史任务详情', JSON.stringify(res))
        if (!utils.isEmptyObject(res) && res.MainData.length > 0) {
          let arr = that.data.cleanitems;
          if (res.MainData[0].CleanStatus == true) {
            arr[0].checked = true
          } else {
            arr[1].checked = true
          }
          console.log(arr)
    
         
          let RatingFileData= res.RatingInfo;
          if (utils.isEmptyObject(RatingFileData)){
            RatingFileData = []
          } else{
            RatingFileData = res.RatingInfo
          }

          that.setData({
            CleanFileData: res.CleanFileData,
            DetailData: res.DetailData,
            MainData: res.MainData[0],
            RatingFileData: RatingFileData,
            title: res.MainData[0].RoomName, //空间名称/页面标题
            cleanitems: arr
          })
          console.log('CleanFileData', JSON.stringify(res.CleanFileData))
          console.log('DetailData', JSON.stringify(res.DetailData))
          console.log('MainData', JSON.stringify(res.MainData[0]))
          console.log('RatingFileData', JSON.stringify(res.RatingFileData))
        }
      },
      function(err) {
        console.error(err)
      })
  },

  //预览保洁图片
  preview(e) {
    let imglist = []
    let index = e.currentTarget.dataset.index;
    imglist = this.data.CleanFileData
    let imgs = [];
    console.log(imglist)
    for (var i = 0; i < imglist.length; i++) {
      imgs.push(this.data.UploadUrl + imglist[i].FilePath)
    }
    console.log(imgs)
    wx.previewImage({
      current: imgs[index],
      urls: imgs,
    })
  },

  //预览租户图片
  previewzuhu(e) {
    let imglist = []
    let index = e.currentTarget.dataset.index;
    imglist = this.data.RatingFileData
    let imgs = [];
    console.log(imglist)
    for (var i = 0; i < imglist[index].RatingFiles.length; i++) {
      imgs.push(this.data.UploadUrl + imglist[index].RatingFiles[i].FilePath)
    }
    console.log(imgs)
    wx.previewImage({
      current: imgs[index],
      urls: imgs,
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    if (options.TaskRowGuid != undefined && options.TaskRowGuid != '') {
      console.log(options.TaskRowGuid)
      this.setData({
        TaskRowGuid: options.TaskRowGuid
      })
      this.GetHistoryCleanTaskDetails()
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})